//
//  LoadingView.m
//  Contacts
//
//  Created by 武 娇 on 14-7-23.
//  Copyright (c) 2014年 李 雷川. All rights reserved.
//

#import "LoadingView.h"
#import "SvGifView.h"
@implementation LoadingView
@synthesize finishAnimationBlock;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor whiteColor];
        NSURL *fileUrl = [[NSBundle mainBundle] URLForResource:@"loading" withExtension:@"gif"];
        SvGifView *_gifView = [[SvGifView alloc] initWithCenter:CGPointMake(self.bounds.size.width / 2, self.bounds.size.height/ 2) fileURL:fileUrl];
        _gifView.backgroundColor = [UIColor clearColor];
        _gifView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
        [self addSubview:_gifView];
        [_gifView startGif];
        _gifView.block = ^{
            self.backgroundColor = [UIColor clearColor];
            [self finishAnimation];
        };
       
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

-(void)finishAnimation{
    if (self.finishAnimationBlock) {
        self.finishAnimationBlock();
    }
    
}

@end
